/*!
 * @mainpage PlacesParser
 *
 * Dieses Programm oeffnet sqlite3 "History" Datenbanken wie z.B.:
 * 'places.sqlite' des Mozilla Firefox Browsers oder
 * 'mmssms.db' von Android Smartphones.
 * Es kann eine Datenbank geoeffnet werden, oder ein gesamtes
 * Verzeichnis rekursiv.
 * Es ist danach moeglich die Ergebnisse in die Zwischenablage
 * zu kopieren und weiter zu verwenden.
 * !!! Da es sich um eine Betaversion handelt, sind die Ausgaben
 * vorerst jedoch noch zu ueberpruefen. !!!
 * <br>
 * <br>
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * <br>
 * <br>
 * @author Alexander Kaspar (alexander.kaspar@gmail.com)
 *
 *
 * @file main.cpp
 * @brief This is the main file in this project
 */

#include <QtGui/QApplication>
#include "mainwindow.h"

/*! @brief A sqlite3 file parser
 * @callgraph
 * @callergraph
 *
 * @param argc int Argument count
 * @param argv char * None or Path to places.sqlite File
 * @return int Return Code of exec()
 */
int main(int argc, char *argv[])
{
    MainWindow *w;
    QApplication a(argc, argv);
    QStringList args = QApplication::arguments();
    QString locale = QLocale::system().name();
    QPoint pos;
    QSize size;

    QString templatePath = QApplication::applicationDirPath () + "/templates";
    if(!QFile(templatePath + "/PPSettings.ini").exists()) {
        qDebug() << "ini file does not exists";
        locale = "en";
    }
    else {
        QSettings settings (templatePath + "/PPSettings.ini", QSettings::IniFormat);
        settings.beginGroup("Language");
        locale = settings.value("lang", "en").toString();
        settings.endGroup();
        settings.beginGroup("LastRun");
        pos = settings.value("winPos", QPoint(100, 100)).toPoint();
        size = settings.value("winSize", QSize(1024, 768)).toSize();
        settings.endGroup();
    }

    QTranslator translator;

    qDebug() << "using language:" << locale;
    translator.load(QString("PlacesParser_") + locale);
    a.installTranslator(&translator);

    if(args.count() > 1) {
        w = new MainWindow(args.at(1), locale, pos, size);
        w->dbName = args.at(1);
    } else
        w = new MainWindow(locale, pos, size);

    w->show();
    int retVal = a.exec();
    delete w;
    return retVal;
}

